package cn.tristenstudy.blog.controller;

import cn.tristenstudy.blog.pojo.Blog;
import cn.tristenstudy.blog.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

/**
 * @author xichen1.li
 * @date 2021-01-13 16:07
 */
@Controller
@RequestMapping("/leeBlog")
public class ArchivesController {

    @Autowired
    private BlogService blogService;

    /**
     * 进入归档页面
     *
     * @param model model
     */
    @GetMapping("/archives")
    public String archives(Model model) {
        Map<String, List<Blog>> map = blogService.archiveBlog();
        Integer blogCount = blogService.getBlogCount();
        model.addAttribute("archivesMap", map);
        model.addAttribute("blogCount", blogCount);
        return "archives";
    }
}
